package com.chuangke.project.controller;                        

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.chuangke.common.db.page.CkPageQuery;
import com.chuangke.common.http.HttpResult;
import com.chuangke.project.domain.ProjectChangeStatusDto;
import com.chuangke.project.model.Project;
import com.chuangke.project.service.ProjectService;             

@RestController                                                  
@RequestMapping("material/project")                              
public class ProjectController {                                 

	@Autowired                                                   
	private ProjectService projectService;                       

	@PreAuthorize("hasAuthority('login:action')")                
	@PostMapping(value = "/save")                                
	public HttpResult save(@RequestBody Project record) {
		projectService.saveOrUpdate(record) ;
		return HttpResult.ok();       
	}                                                            

	@PreAuthorize("hasAuthority('login:action')")                
	@PostMapping(value = "/changeStatus")                              
	public HttpResult changeStatus(@RequestBody ProjectChangeStatusDto param) {
		projectService.changeStatus(param.getIdList(),param.getStatus());
		return HttpResult.ok();
	}                                                            

	@PreAuthorize("hasAuthority('login:action')")                
	@PostMapping(value = "/page")                                
	public HttpResult page(@RequestBody Map<String,Object> params) {                                   
		return HttpResult.ok(projectService.page(new CkPageQuery(params)));   
	}
}                                                                